package river_city_ransom.tests;

import java.util.List;

import river_city_ransom.contracts.Dimensions_C;
import river_city_ransom.contracts.PersonnageJouable_C;
import river_city_ransom.implementations.Dimensions_I;
import river_city_ransom.implementations.Objet_I;
import river_city_ransom.implementations.PersonnageJouable_I;
import river_city_ransom.implementations.Position_I;
import river_city_ransom.services.Dimensions;
import river_city_ransom.services.Objet;
import river_city_ransom.services.PersonnageJouable;
import river_city_ransom.types.ObjetNom;
import tools.Toolbox;
import exceptions.ComposantError;
import junit.framework.TestCase;


public class PersonnageJouable_T extends TestCase {
	public void test_init_ok() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			assertTrue(Toolbox.equals(p.dimensions(), d));
			assertTrue(p.estEquipable() == false);
			assertTrue(p.estPorte() == false);
			assertTrue(p.estJete() == 0);
			assertTrue(Toolbox.equals(p.position(), new Position_I(0, 0, 0)));
			assertTrue(Toolbox.equals(p.nom(), n));
			assertTrue(p.force() == f);
			assertTrue(p.maxPointsDeVie() == pv);
			assertTrue(p.pointsDeVie() == pv);
			assertTrue(p.estVaincu() == false);
			assertTrue(Toolbox.equals(p.choseEquipee(), null));
			assertTrue(p.estEquipe() == false);
			assertTrue(p.estGele() == 0);
			assertTrue(p.versLaDroite() == true);
			assertTrue(p.sommeDArgent() == 0);
			assertTrue(p.poche().isEmpty());
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_init_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_init_ko_1() {
		try {
			String n = "";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			System.err.println("Personnage::test_init_ko_1\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_init_ko_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = -15, pv = 100;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			System.err.println("Personnage::test_init_ko_2\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_init_ko_3() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = -100;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			System.err.println("Personnage::test_init_ko_3\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_deposerArgent_ok() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, a = 100;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			int sda_pre = p.sommeDArgent();
			p.deposerArgent(a);
			assertTrue(p.sommeDArgent() == sda_pre + a);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_deposerArgent_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_deposerArgent_ko() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, a = -100;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.deposerArgent(a);
			System.err.println("Personnage::test_deposerArgent_ko\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_retirerArgent_ok() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, a1 = 100, a2 = 50;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.deposerArgent(a1);
			int sda_pre = p.sommeDArgent();
			p.retirerArgent(a2);
			assertTrue(p.sommeDArgent() == sda_pre - a2);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_retirerArgent_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_retirerArgent_ko_1() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, a1 = 100, a2 = -50;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.deposerArgent(a1);
			p.retirerArgent(a2);
			System.err.println("Personnage::test_retirerArgent_ko_1\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_retirerArgent_ko_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, a1 = 50, a2 = 200;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.deposerArgent(a1);
			p.retirerArgent(a2);
			System.err.println("Personnage::test_retirerArgent_ko_2\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_ranger_ok() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o = new Objet_I(ObjetNom.UN_DOLLAR);
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			List<Objet> po_pre = p.poche();
			p.ranger(o);
			po_pre.add(o);
			assertTrue(Toolbox.equals(p.poche(), po_pre));
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_ranger_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_ranger_ko_1() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o = new Objet_I(ObjetNom.CHAINE_DE_VELO);
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.ranger(o);
			System.err.println("Personnage::test_ranger_ko_1\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_ranger_ko_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o = new Objet_I(ObjetNom.UN_DOLLAR);
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.retirerPointsDeVie(pv);
			p.ranger(o);
			System.err.println("Personnage::test_ranger_ko_2\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_vendre_ok() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o = new Objet_I(ObjetNom.UN_DOLLAR);
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.ranger(o);
			List<Objet> po_pre = p.poche();
			int sda_pre = p.sommeDArgent();
			p.vendre(o);
			po_pre.remove(o);
			assertTrue(Toolbox.equals(p.poche(), po_pre));
			assertTrue(p.sommeDArgent() == sda_pre + o.valeur());
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_vendre_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_vendre_ko_1() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o = new Objet_I(ObjetNom.UN_DOLLAR);
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.vendre(o);
			System.err.println("Personnage::test_vendre_ko_1\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_vendre_ko_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, g = 5;
			Objet o = new Objet_I(ObjetNom.UN_DOLLAR);
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.ranger(o);
			p.geler(g);
			p.vendre(o);
			System.err.println("Personnage::test_vendre_ko_2\n\tException non lev�e.");
			fail("Exception non lev�e.");
		}
		catch(ComposantError e) {
		}
	}
}
